<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/publicPage.jsp"%>
<html>
<head>
    <title>编辑信息</title>
    <meta http-equiv="Content-Type" content="application/msword; charset=gb2312" />
    <%@ include file="/publicLink.jsp"%>
    <%@ include file="/publicjQueryJS.jsp"%>
    <%@ include file="/publicFormJS.jsp"%>
    <%@ include file="/publicValidation.jsp"%>
    <script type="text/javascript">
        var eee;
        $(function (){
            $.metadata.setType("attr", "validate");
            var v = $("form").validate({
                rules:{
                    valveName:{
                        remote:"/rest/valve/valveOnly?id="+$("#valveTableId").val()
                    }
                },
                messages:{
                    valveName:{
                        remote:$.format("数据已经存在，请重新填写！")
                    }
                },
                //调试状态，不会提交数据的
                debug: true,
                errorPlacement: function (lable, element) {
                    if (element.hasClass("l-textarea")) {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },
                success: function (lable) {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea")) {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },
                submitHandler: function ()
                {
                    $("form .l-text,.l-textarea").ligerHideTip();
                    var type=$("#type").val();
                    if(type=="add"){
                        $.ajax({
                            type:"POST",
                            url:'/rest/valve/valveAdd',
                            data: $('#formValve').serialize(),
                            async: false,
                            success: function (data) {
                                window.parent.okdialog();
                                window.parent.loadData();
                                window.parent.closeDialog();
                            },
                            error: function (request) {
                                $.ligerDialog.success('操作失败!', function ()
                                {
                                    window.parent.loadData();
                                    //window.parent.closeDialog();
                                });
                            }
                        });
                    }
                    //如果是type是修改
                    if(type=="update"){
                        $.ajax({
                            type:"POST",
                            url:'/rest/valve/valveUpdate',
                            data: $('#formValve').serialize(),
                            async: false,
                            success: function (data) {
                                window.parent.okdialog();
                                window.parent.loadData();
                                window.parent.closeDialog();
                            },
                            error: function (request) {
                                $.ligerDialog.success('操作失败!', function ()
                                {
                                    window.parent.loadData();
                                    //window.parent.closeDialog();
                                });
                            }
                        });
                    }

                }
            });
            $("form").ligerForm();
            $(".l-button-test").click(function (){
                //关闭填出框
                window.parent.closeDialog();
                //验证
                //alert(v.element($("#txtName")));
            });
        });


        $(function(){
        });
    </script>
    <style type="text/css">
        .l-table-edit {}
        .l-table-edit-td{ padding:4px;font-size:13px;}
        .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
    </style>

</head>

<body style="padding:10px">
<form name="formValve" method="post" action="" id="formValve">
    <div>
    </div>
    <table cellpadding="0" cellspacing="0" class="l-table-edit" >
        <tr>
            <td  align="right" class="l-table-edit-td">消息名:</td>
            <td  align="left" class="l-table-edit-td"><input name="valveName" value="${valveTable.valveName}" type="text" id="valveName" ltype="text" validate="{required:true,minlength:1,maxlength:10}" /></td>
            <td  align="left"><input name="valveTableId" id="valveTableId" value="${valveTable.valveTableId}" type="hidden"><input id="type" value="${type}" type="hidden"></td>

        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">是否启用:</td>
            <td align="left" class="l-table-edit-td">
                <input id="rbtnl_0" type="radio" name="enabled" value="0" ${valveTable.enabled eq 0? 'checked="checked"':''}  /><label for="rbtnl_0">否</label> <input id="rbtnl_1" type="radio" name="enabled" checked="checked" value="1" ${valveTable.enabled eq 1? 'checked="checked"':''} /><label for="rbtnl_1">是</label>
            </td>
        </tr>
    </table>
    <br />
    <input type="submit" value="提交" id="Button1" class="l-button l-button-submit" />
    <input type="reset" value="关闭" class="l-button l-button-test"/>
</form>
</body>
</html>
